#include "manualservondialog.h"
#include "ui_manualservondialog.h"
#include <QSettings>
#include "hmicommondefine.h"
#include <QMessageBox>

ManualServonDialog::ManualServonDialog(int styleId,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ManualServonDialog)
{
    ui->setupUi(this);
    move(0,0);
    initialDisplayStyle(styleId);
//#ifdef BUILD_ARM
//    setGeometry(70,128,460,595);
//#endif

    servonStatus = 0;

    this->setWindowFlags(Qt::FramelessWindowHint);    //无边框
    this->setStyleSheet("outline: none;");            //无虚线框
}

void ManualServonDialog::initialDisplayStyle(int styleId)
{
    switch (styleId) {
    case 1:
        this->setGeometry(0,0,600,450);
        ui->returnBtn->setGeometry(500,400,70,40);
        break;
    default:
        break;
    }
}

ManualServonDialog::~ManualServonDialog()
{
    delete ui;
}

void ManualServonDialog::updateView()
{
    if(servonStatus == 0)
    {
        ui->servonBtn->setText(tr("开启"));
    }
    else if(servonStatus == 1)
    {
        ui->servonBtn->setText(tr("关闭"));
    }
}

void ManualServonDialog::updateViewFromTopSlot(int servonStatus)
{
    this->servonStatus = servonStatus;
    if(servonStatus == 0)
    {
        ui->servonBtn->setText(tr("开启"));
    }
    else if(servonStatus == 1)
    {
        ui->servonBtn->setText(tr("关闭"));
    }
}

void ManualServonDialog::changeLanguage()
{
    ui->retranslateUi(this);
}

void ManualServonDialog::on_returnBtn_clicked()
{
        this->hide();
}

void ManualServonDialog::on_servonBtn_clicked()
{
    if(servonStatus == 0)
    {
        emit servonBtnSignals(1);
        ui->servonBtn->setText(tr("关闭"));

        servonStatus = 1;
    }
    else if (servonStatus == 1)
    {
        emit servonBtnSignals(0);
        ui->servonBtn->setText(tr("开启"));

        servonStatus = 0;
    }
    //this->hide();
}

void ManualServonDialog::on_button_setJogMaxTime_clicked()
{
    QSettings settings(D_MODULE_CONFIG_PATH, QSettings::IniFormat);
    settings.setValue("Module/allowMaxJogTime", ui->lineEdit_jogMaxTime->text().toInt());
    emit setMaxJogTime_signal(ui->lineEdit_jogMaxTime->text().toInt());
    QMessageBox::information(this,"提示","设置完成",QMessageBox::StandardButton::Ok);
}
